﻿'Bram Debouvere
'Clinciu Andrei
Option Strict On

Imports System.Text.RegularExpressions
Imports System.Collections.Generic

Public Class Validation
    'validates the string someone cat put into the inputbox in the giftlistwizard (change amount button)
    Public Shared Function checkGiftListWizardAantalInputString(ByRef str As String) As Boolean
        If IsNumeric(str) Then
            If (CInt(str) <= 100 And CInt(str) >= 1) Then
                Return True
            End If
        End If
        Return False
    End Function

    'validates all stuff in the addperson form, and returns a message in the byref err
    Public Shared Function validatePerson(ByRef name As String, ByRef familyName As String, ByRef adress As String, ByRef postcode As String, ByRef country As String, ByRef email As String, ByRef phone As String, ByRef mobile As String, ByRef err As String) As Boolean
        If name.Length < 2 Then
            err = "Vul de naam in, 2 karakters minimum"
            Return False
        End If
        If familyName.Length < 2 Then
            err = "Vul de familienaam in, 2 karakters minimum"
            Return False
        End If
        If adress.Length < 4 Then
            err = "Vul het adres in, 4 karakters minimum"
            Return False
        End If
        If (postcode.Length <> 4 And postcode.Length <> 5) OrElse Not IsNumeric(postcode) Then
            err = "Vul een geldige postcode in, 4 karakters minimum, 5 maximum"
            Return False
        End If
        If country.Length < 2 Then
            err = "Vul het land in, 2 karakters minimum"
            Return False
        End If
        If Not email = "" AndAlso Not validateEmail(email) Then
            err = "Vul een geldig emailadres in!"
            Return False
        End If

        If Not phone = "" AndAlso Not IsNumeric(phone) Then
            err = "Vul het telefoonnummer juist in"
            Return False
        End If
        If Not phone = "" AndAlso Not IsNumeric(phone) Then
            err = "Vul het mobiel nummer juist in"
            Return False
        End If

        Return True
    End Function

    'validates email
    Public Shared Function validateEmail(ByRef EmailAddress As String) As Boolean
        Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
        Dim emailAddressMatch As Match = Regex.Match(EmailAddress, pattern)
        Return emailAddressMatch.Success
    End Function

    Shared Function ValidateProduct(ByVal naam As String, ByVal omschrijving As String, ByVal prijs As String) As Dictionary(Of String, Boolean)
        Dim dictionary As New Dictionary(Of String, Boolean)
        Dim isValid As Boolean = True
        If naam.Length < 3 Then
            dictionary.Add("txtNaam", False)
            isValid = False
        Else
            dictionary.Add("txtNaam", True)
        End If
        If omschrijving.Length < 10 Then
            dictionary.Add("txtOmschrijving", False)
            isValid = False
        Else
            dictionary.Add("txtOmschrijving", True)
        End If
        If Not IsNumeric(prijs) Then
            dictionary.Add("txtPrijs", False)
            isValid = False
        Else
            dictionary.Add("txtPrijs", True)
        End If
        dictionary.Add("isValid", isValid)
        Return dictionary
    End Function


End Class
